namespace Delphi.Mimir.Migrations
{
    using System;
    using System.Data.Entity.Migrations;
    
    public partial class AddFundamentals : DbMigration
    {
        public override void Up()
        {
            CreateTable(
                "fin.eod_fundamentals",
                c => new
                    {
                        fun_id = c.Long(nullable: false, identity: true),
                        fun_sym_id = c.Int(nullable: false),
                        fun_ind_id = c.Int(nullable: false),
                        fun_sct_id = c.Int(nullable: false),
                        fun_dt = c.DateTime(nullable: false),
                        fun_shares = c.Long(),
                        fun_market_cap = c.Long(),
                        fun_pe = c.Decimal(precision: 18, scale: 6),
                        fun_eps = c.Decimal(precision: 18, scale: 6),
                        fun_div_yield = c.Decimal(precision: 18, scale: 6),
                        fun_ebitda = c.Long(),
                        fun_peg = c.Decimal(precision: 18, scale: 6),
                        fun_pts = c.Decimal(precision: 18, scale: 6),
                        fun_ptb = c.Decimal(precision: 18, scale: 6),
                        fun_yield = c.Decimal(precision: 18, scale: 6),
                    })
                .PrimaryKey(t => t.fun_id)
                .ForeignKey("fin.eod_industries", t => t.fun_ind_id, cascadeDelete: true)
                .ForeignKey("fin.eod_sectors", t => t.fun_sct_id, cascadeDelete: true)
                .ForeignKey("fin.eod_symbols", t => t.fun_sym_id, cascadeDelete: true)
                .Index(t => new { t.fun_sym_id, t.fun_dt }, unique: true, name: "IX_FUN")
                .Index(t => t.fun_ind_id)
                .Index(t => t.fun_sct_id);
            
            CreateTable(
                "fin.eod_industries",
                c => new
                    {
                        ind_id = c.Int(nullable: false, identity: true),
                        ind_cd = c.String(nullable: false, maxLength: 25, unicode: false),
                        ind_desc = c.String(nullable: false, maxLength: 250, unicode: false),
                    })
                .PrimaryKey(t => t.ind_id);
            
            CreateTable(
                "fin.eod_sectors",
                c => new
                    {
                        sct_id = c.Int(nullable: false, identity: true),
                        sct_cd = c.String(nullable: false, maxLength: 25, unicode: false),
                        sct_desc = c.String(nullable: false, maxLength: 250, unicode: false),
                    })
                .PrimaryKey(t => t.sct_id);
            
            CreateTable(
                "raw.eod_fundamentals",
                c => new
                    {
                        fun_id = c.Long(nullable: false, identity: true),
                        fun_sym_cd = c.String(nullable: false, maxLength: 25, unicode: false),
                        fun_exc_cd = c.String(nullable: false, maxLength: 25, unicode: false),
                        fun_dt = c.DateTime(nullable: false),
                        fun_ind_desc = c.String(maxLength: 250, unicode: false),
                        fun_sct_desc = c.String(maxLength: 250, unicode: false),
                        fun_shares = c.Long(),
                        fun_market_cap = c.Long(),
                        fun_pe = c.Decimal(precision: 18, scale: 6),
                        fun_eps = c.Decimal(precision: 18, scale: 6),
                        fun_div_yield = c.Decimal(precision: 18, scale: 6),
                        fun_ebitda = c.Long(),
                        fun_peg = c.Decimal(precision: 18, scale: 6),
                        fun_pts = c.Decimal(precision: 18, scale: 6),
                        fun_ptb = c.Decimal(precision: 18, scale: 6),
                        fun_yield = c.Decimal(precision: 18, scale: 6),
                    })
                .PrimaryKey(t => t.fun_id);
            
        }
        
        public override void Down()
        {
            DropForeignKey("fin.eod_fundamentals", "fun_sym_id", "fin.eod_symbols");
            DropForeignKey("fin.eod_fundamentals", "fun_sct_id", "fin.eod_sectors");
            DropForeignKey("fin.eod_fundamentals", "fun_ind_id", "fin.eod_industries");
            DropIndex("fin.eod_fundamentals", new[] { "fun_sct_id" });
            DropIndex("fin.eod_fundamentals", new[] { "fun_ind_id" });
            DropIndex("fin.eod_fundamentals", "IX_FUN");
            DropTable("raw.eod_fundamentals");
            DropTable("fin.eod_sectors");
            DropTable("fin.eod_industries");
            DropTable("fin.eod_fundamentals");
        }
    }
}
